<div class="lazy-timeline">
  {#if timelineComponent}
    <svelte:component this={timelineComponent} {timeline} />
  {/if}
</div>
<style>
  .lazy-timeline {
    width: 100%;
  }
</style>
<script>
  import { store } from '../../_store/store.js'
  import { importLoggedInStoreExtensions } from '../../_utils/asyncModules/importLoggedInStoreExtensions.js'
  import { importTimeline } from '../../_utils/asyncModules/importTimeline.js'

  export default {
    async oncreate () {
      console.log('LazyTimeline oncreate')
      const { currentInstance } = this.store.get()
      const { timeline } = this.get()
      const [timelineComponent] = await Promise.all([
        importTimeline(),
        importLoggedInStoreExtensions()
      ])
      this.store.set({ currentTimeline: timeline })
      this.store.setForTimeline(currentInstance, timeline, { runningUpdate: false })
      this.set({ timelineComponent })
    },
    store: () => store,
    data: () => ({
      timelineComponent: undefined
    })
  }
</script>
